package com.burstly.lib.component.networkcomponent.burstly.html.ormma;

import android.content.Context;
import android.os.StatFs;
import android.webkit.JavascriptInterface;
import com.burstly.lib.constants.UriConstants;
import com.burstly.lib.util.LoggerExt;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class OrmmaAssetController extends OrmmaController
{
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String TAG = "OrmmaAssetController";

  public OrmmaAssetController(OrmmaView paramOrmmaView, Context paramContext)
  {
    super(paramOrmmaView, paramContext);
  }

  public static boolean deleteDirectory(File paramFile)
  {
    if (paramFile.exists())
    {
      File[] arrayOfFile = paramFile.listFiles();
      int i = 0;
      if (i < arrayOfFile.length)
      {
        if (arrayOfFile[i].isDirectory())
          deleteDirectory(arrayOfFile[i]);
        while (true)
        {
          i++;
          break;
          arrayOfFile[i].delete();
        }
      }
    }
    return paramFile.delete();
  }

  private String getFilesDir()
  {
    return this.mContext.getFilesDir().getPath();
  }

  private String readStream(InputStream paramInputStream)
    throws IOException
  {
    byte[] arrayOfByte = new byte[1024];
    ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
    while (true)
    {
      int i = paramInputStream.read(arrayOfByte);
      String str;
      if (i <= 0)
        str = localByteArrayOutputStream.toString();
      try
      {
        localByteArrayOutputStream.close();
        return str;
        localByteArrayOutputStream.write(arrayOfByte, 0, i);
      }
      catch (IOException localIOException)
      {
        while (true)
          LOG.logThrowable("OrmmaAssetController", localIOException);
      }
    }
  }

  @JavascriptInterface
  public int cacheRemaining()
  {
    StatFs localStatFs = new StatFs(this.mContext.getFilesDir().getPath());
    return localStatFs.getFreeBlocks() * localStatFs.getBlockSize();
  }

  public void deleteOldAds()
  {
    String str = getFilesDir();
    deleteDirectory(new File(str + File.separator + "ad"));
  }

  public String prepareWrappedContentString(String paramString1, String paramString2)
  {
    int i;
    StringBuilder localStringBuilder1;
    StringBuilder localStringBuilder2;
    String str1;
    String str2;
    if (paramString1.indexOf("<html") >= 0)
    {
      i = 1;
      localStringBuilder1 = new StringBuilder(paramString1);
      localStringBuilder2 = new StringBuilder();
      UriConstants localUriConstants = UriConstants.getInstance();
      str1 = localUriConstants.getContentRoot() + "/lib/ormma_android_v1.js";
      str2 = localUriConstants.getContentRoot() + "/lib/ormma_bridge_android_v1.js";
      if (i == 0)
        break label192;
      if (localStringBuilder1.indexOf("/ormma_bridge.js") <= 0)
        break label156;
      label99: if (localStringBuilder1.indexOf("/ormma.js") <= 0)
        break label174;
    }
    while (true)
    {
      localStringBuilder2.append(localStringBuilder1);
      if (i == 0)
      {
        localStringBuilder2.append("</div> ");
        localStringBuilder2.append("</body> ");
        localStringBuilder2.append("</html> ");
      }
      return localStringBuilder2.toString();
      i = 0;
      break;
      label156: LOG.logError("OrmmaAssetController", "ormma_bridge.js script hasn`t been found in HTML!", new Object[0]);
      break label99;
      label174: LOG.logError("OrmmaAssetController", "ormma.js script hasn`t been found in HTML!", new Object[0]);
      continue;
      label192: localStringBuilder2.append("<html>");
      localStringBuilder2.append("<head>");
      localStringBuilder2.append("<meta name='viewport' content='user-scalable=no initial-scale=1.0' />");
      localStringBuilder2.append("<title>Advertisement</title> ");
      localStringBuilder2.append("<script src=\"").append(str2).append("\" type=\"text/javascript\"></script>");
      localStringBuilder2.append("<script src=\"").append(str1).append("\" type=\"text/javascript\"></script>");
      if (paramString2 != null)
      {
        localStringBuilder2.append("<script type=\"text/javascript\">");
        localStringBuilder2.append(paramString2);
        localStringBuilder2.append("</script>");
      }
      localStringBuilder2.append("</head>");
      localStringBuilder2.append("<body style=\"margin:0; padding:0; overflow:hidden; background-color:transparent;\">");
      localStringBuilder2.append("<div align=\"center\"> ");
    }
  }

  public String readStreamAndPrepareWrappedContentString(InputStream paramInputStream, String paramString)
    throws IOException
  {
    return prepareWrappedContentString(readStream(paramInputStream), paramString);
  }

  public void stopAllListeners()
  {
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.burstly.html.ormma.OrmmaAssetController
 * JD-Core Version:    0.6.2
 */